//
//  HomeTaskView.m
//  Fireball
//
//  Created by app on 2018/7/12.
//  Copyright © 2018年 俞渊华. All rights reserved.
//

#import "HomeTaskView.h"
@interface HomeTaskView ()
@property(nonatomic, strong)UILabel *taskLabel;
@property(nonatomic, strong)UILabel *gongdanLabel;
@property(nonatomic, strong)UILabel *personLabel;
@property(nonatomic, strong)UILabel *startLabel;
@property(nonatomic, strong)UIImageView *workPerson;
@property(nonatomic, strong)UIImageView *workTime;
@property(nonatomic, strong)UIImageView *workName;

@end
@implementation HomeTaskView

-(instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        self.taskLabel = [[UILabel alloc]init];
        self.taskLabel.textColor = [UIColor xm_colorFromRGB:0x858C96];
        self.taskLabel.font = [UIFont xm_font:15.0];
//        [self addSubview:self.taskLabel];
        
        self.gongdanLabel = [[UILabel alloc]init];
        self.gongdanLabel.textColor = [UIColor xm_colorFromRGB:0x858C96];
        self.gongdanLabel.font = [UIFont xm_font:13.0];
        [self addSubview:self.gongdanLabel];
        
        self.personLabel = [[XMLabel alloc]init];
        self.personLabel.layer.masksToBounds = YES;
        self.personLabel.layer.cornerRadius = 8.0;
        self.personLabel.textColor= [UIColor xm_colorFromRGB:0x858C96];
        self.personLabel.font = [UIFont xm_font:12.0];
        if (IS_IPHONE_5) {
            self.personLabel.font = [UIFont xm_font:10.0];

        }
//        self.personLabel.edgeInsets = UIEdgeInsetsMake(3, 10, 3, 10);
        [self addSubview:self.personLabel];
        //工单名字
        self.startLabel = [[UILabel alloc]init];
        self.startLabel.textColor = [UIColor xm_colorFromRGB:0x858C96];
        self.startLabel.font = [UIFont xm_font:12.0];
        [self addSubview:self.startLabel];
//        self.startLabel.hidden=YES;
        
        self.workPerson=[[UIImageView alloc] init];
        [self.workPerson setImage:[UIImage imageNamed:@"workorder_icon_person"]];
        [self addSubview:self.workPerson];
        
        self.workTime=[[UIImageView alloc] init];
        [self.workTime setImage:[UIImage imageNamed:@"workorder_icon_time"]];
        [self addSubview:self.workTime];
        
        self.workName=[[UIImageView alloc] init];
        [self.workName setImage:[UIImage imageNamed:@"workorder_icon_name"]];
        [self addSubview:self.workName];
    }
    return self;
}
-(void)setModel:(WorkOrderModel *)model{
    _model = model;
//        self.taskLabel.text = @"巡逻任务";
    
    NSString*str=model.proposalStartTime;
    
    NSTimeInterval time=[str doubleValue]/1000;

    self.personLabel.text = [NSString stringWithFormat:@"建议开始时间: %@",[self timestampSwitchTime:time andFormatter:@"YYYY-MM-dd HH:mm"]];
    self.gongdanLabel.text = [NSString stringWithFormat:@"执行人员: %@",model.userName];
//    self.personLabel.text = [NSString stringWithFormat:@"开始时间: %@",model.proposalStartTime];
    self.startLabel.text = [NSString stringWithFormat:@"%@",model.workOrderName];

//    self.tagLabel.text = _model.Tag;
//    self.timeLabel.text = [XMTool  timeIntervalFromLastTime:_model.UpdateTime];
//
//    self.souceLabel.text = _model.Souce;
//    if ([_model.Tag isEqualToString:@"热门"]) {
//        self.tagLabel.hidden = NO;
//
//        self.tagLabel.backgroundColor = [UIColor xm_colorFromRGB:0xff0000 alpha:0.04];
//        self.tagLabel.textColor = [UIColor xm_colorFromRGB:0xFF6666];
//    }else if ([_model.Tag isEqualToString:@"推荐"]){
//        self.tagLabel.hidden = NO;
//
//        self.tagLabel.backgroundColor = [UIColor xm_colorFromRGB:0x212832 alpha:0.04];
//        self.tagLabel.textColor = [UIColor xm_colorFromRGB:0x1B88EE];
//    }else{
//        self.tagLabel.hidden = YES;
//    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
//    [self.taskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.centerX.mas_equalTo(self);
//    }];
    [self.gongdanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).offset(0);
        make.left.mas_equalTo(self.workPerson.mas_right).offset(5);
        make.centerY.mas_equalTo(self.workPerson);
    }];
    
    [self.personLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(self);
        make.left.mas_equalTo(self.workTime.mas_right).offset(5);
//        make.top.mas_equalTo(self.gongdanLabel.mas_bottom).offset(5);
        make.centerY.mas_equalTo(self.workTime);

    }];
    
    [self.startLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(self);
        make.left.mas_equalTo(self.workName.mas_right).offset(5);
        make.top.mas_equalTo(self.personLabel.mas_bottom).offset(5);

    }];
    
    [self.workPerson mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).offset(0);
        make.width.height.mas_equalTo(@20);
    }];
    
    [self.workTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.workPerson.mas_bottom).offset(3);
        make.width.height.mas_equalTo(@20);
    }];
    
    [self.workName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.workTime.mas_bottom).offset(3);
        make.width.height.mas_equalTo(@20);
        make.centerY.mas_equalTo(self.startLabel);

    }];
    
}
-(void)drawRect:(CGRect)rect{
    [super drawRect:rect];
}
#pragma mark - 将某个时间戳转化成 时间

-(NSString *)timestampSwitchTime:(NSInteger)timestamp andFormatter:(NSString *)format{
    
    
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    [formatter setDateFormat:format]; // （@"YYYY-MM-dd hh:mm:ss"）----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
    
    [formatter setTimeZone:timeZone];
    
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timestamp];
    
//    NSLog(@"1296035591  = %@",confromTimesp);
    
    
    
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    
    
    
    //NSLog(@"&&&&&&&confromTimespStr = : %@",confromTimespStr);
    
    
    
    return confromTimespStr;
    
}

@end
